package com.atguigu.zy.interview.juc.locks;

import com.atguigu.zy.interview.juc.enums.CountryEnum;

import java.util.concurrent.CountDownLatch;

/**
 * @Author : Jungle
 * @Description : 闭锁
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                try {
                    System.out.println(Thread.currentThread().getName() + "\t 国，被灭");
                } finally {
                    countDownLatch.countDown();
                }
            }, CountryEnum.forEach_CountryEnum(i).getRetMsg()).start();
        }

        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t *********** 秦帝国，一统华夏");
        System.out.println();
        /**
         * 下面相当于取表名和每个字段的属性
         */
        System.out.println(CountryEnum.ONE);
        System.out.println(CountryEnum.ONE.getRetCode());
        System.out.println(CountryEnum.ONE.getRetMsg());
    }


    private static void closeDoor() throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t 上完自习，离开教室");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t 班长最后关门走人");
    }
}
